from django.template import Variable, VariableDoesNotExist
from django.template.context import Context

def resolve_variable(variable,  context,  default = None):
    try:
        resolved_variable = Variable(variable).resolve(context)
    except VariableDoesNotExist:
        if default == None:
            resolved_variable = None
        else:
            resolved_variable = default
    return resolved_variable

def copy_context(context):
    new_context = Context(dict_ = context)
    return new_context